package com.ohs.ohsoa.system.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.ohs.ohsoa.system.dto.WorkNotesDto;
import com.ohs.ohsoa.system.entity.WorkNotes;
import com.ohs.ohsoa.system.mapper.WorkNotesMapper;
import com.ohs.ohsoa.system.vo.WorkNotesNumberVo;
import com.ohs.ohsoa.system.vo.WorkNotesVo;
import com.ohs.ohsoa.utils.bean.requestBean.PageParam;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 工作笔记实现类
 *
 * @author ss
 *
 */
@Service
public class WorkNotesServiceImpl extends ServiceImpl<WorkNotesMapper, WorkNotes> implements WorkNotesService {

    @Resource
    private WorkNotesMapper workNotesMapper;


    @Override
    public List<WorkNotesVo> workNotesSelectList(PageParam<WorkNotesDto> pageParam) {
        // 获取工作笔记对象
        WorkNotesDto workNotesDto = pageParam.getSearchbean();
        // 分页
        PageHelper.startPage(pageParam.getIndexPage(), pageParam.getPageSize());
       return workNotesMapper.workNotesSelectList(workNotesDto);
    }


    @Override
    public WorkNotesVo workNotesSelect(WorkNotesDto workNotesDto) {
        return workNotesMapper.workNotesSelect(workNotesDto);
    }

    @Override
    public Boolean workNotesInsert(WorkNotesDto workNotesDto) {
        WorkNotes workNotes = new WorkNotes();
        BeanUtils.copyProperties(workNotesDto,workNotes);
        // 设置创建时间
        workNotes.setCreateTime(LocalDateTime.now().toString());
        return this.save(workNotes);
    }

    @Override
    public Boolean workNotesDelete(WorkNotesDto workNotesDto) {
        return workNotesMapper.workNotesDelete(workNotesDto.getWorkNotesGuids());
    }

    @Override
    public Boolean workNotesUpdate(WorkNotesDto workNotesDto) {
        WorkNotes workNotes = new WorkNotes();
        BeanUtils.copyProperties(workNotesDto,workNotes);
        return this.updateById(workNotes);
    }

    @Override
    public List<WorkNotesNumberVo> worktypeSelect(WorkNotesDto workNotesDto) {
        return workNotesMapper.worktypeSelect(workNotesDto);
    }

}
